package com.ruoyi.web.controller.inspection;

import java.util.List;

import com.ruoyi.inspection.domain.FzInspectionPlanRoute;
import com.ruoyi.inspection.service.IFzInspectionPlanRouteService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计划路线Controller
 * 
 * @author ruoyi
 * @date 2020-03-13
 */
@Controller
@RequestMapping("/inspection/routeplan")
public class FzInspectionPlanRouteController extends BaseController
{
    private String prefix = "inspection/routeplan";

    @Autowired
    private IFzInspectionPlanRouteService fzInspectionPlanRouteService;

    @RequiresPermissions("inspection:route:view")
    @GetMapping()
    public String route()
    {
        return prefix + "/route";
    }

    /**
     * 查询计划路线列表
     */
    @RequiresPermissions("inspection:route:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FzInspectionPlanRoute fzInspectionPlanRoute)
    {
        startPage();
        List<FzInspectionPlanRoute> list = fzInspectionPlanRouteService.selectFzInspectionPlanRouteList(fzInspectionPlanRoute);
        return getDataTable(list);
    }

    /**
     * 导出计划路线列表
     */
    @RequiresPermissions("inspection:route:export")
    @Log(title = "计划路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzInspectionPlanRoute fzInspectionPlanRoute)
    {
        List<FzInspectionPlanRoute> list = fzInspectionPlanRouteService.selectFzInspectionPlanRouteList(fzInspectionPlanRoute);
        ExcelUtil<FzInspectionPlanRoute> util = new ExcelUtil<FzInspectionPlanRoute>(FzInspectionPlanRoute.class);
        return util.exportExcel(list, "route");
    }

    /**
     * 新增计划路线
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存计划路线
     */
    @RequiresPermissions("inspection:route:add")
    @Log(title = "计划路线", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzInspectionPlanRoute fzInspectionPlanRoute)
    {
        return toAjax(fzInspectionPlanRouteService.insertFzInspectionPlanRoute(fzInspectionPlanRoute));
    }

    /**
     * 修改计划路线
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        FzInspectionPlanRoute fzInspectionPlanRoute = fzInspectionPlanRouteService.selectFzInspectionPlanRouteById(id);
        mmap.put("fzInspectionPlanRoute", fzInspectionPlanRoute);
        return prefix + "/edit";
    }

    /**
     * 修改保存计划路线
     */
    @RequiresPermissions("inspection:route:edit")
    @Log(title = "计划路线", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzInspectionPlanRoute fzInspectionPlanRoute)
    {
        return toAjax(fzInspectionPlanRouteService.updateFzInspectionPlanRoute(fzInspectionPlanRoute));
    }

    /**
     * 删除计划路线
     */
    @RequiresPermissions("inspection:route:remove")
    @Log(title = "计划路线", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzInspectionPlanRouteService.deleteFzInspectionPlanRouteByIds(ids));
    }
}
